<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        .left-enter-active {
            animation: left 1.5s;
        }

        /* 离开激活 */
        .left-leave-active {
            animation: left 1.5s reverse;  /* 逆向渲染 */
        }

        @keyframes left {
            0% { 
                opacity: 0;
                transform: translateX(-100%);
            }
            100% { 
                opacityopacity: 1; 
                transform:translateX(0px);
            
            }

        }

        .right-enter-active {
            animation: right 1.5s;
        }

        /* 离开激活 */
        .right-leave-active {
            animation: right 1.5s reverse;  /* 逆向渲染 */
        }

        @keyframes right {
            0% { 
                opacity: 0;
                transform: translateX(100%);
            }
            100% { 
                opacityopacity: 1; 
                transform:translateX(0px);
            
            }

        }
    </style>
</head>
<body>
    <div id="box">
        <navbar @myevent="change"></navbar>

      
        <sidebar v-show="isShow" direction="right"></sidebar>
      
    </div>

    <script type="text/javascript">
    Vue.component("navbar", {
        template:`
        <div style="background:yellow;">
            导航栏 -- <button @click="handleClick">click</button>
        </div>
        `, 
        methods: {
            handleClick () {
                this.$emit("myevent")
            }
        }
    })
 
    Vue.component("sidebar",{
        props:["direction"],
        template:`
        <transition :name="direction">
        <div style="background:red; width: 200px;">
            <ul>
                <li>好友</li>
                <li>设置</li>
                <li>退出</li>
            </ul>
        </div>
        </transition>
            `
        })

        new Vue ({
            el: "#box",
            data: {
                isShow: false
            },
            methods:{
                change(){
                    this.isShow = !this.isShow
                }
            }
        })

    </script>
</body>
</html>